package com.android.common.utils;

import android.text.InputFilter;
import android.text.Spanned;
import java.util.regex.Pattern;

public class InputUtils {

    public static InputFilter[] getCommonFilter(int maxLength) {
        return new InputFilter[]{new InputFilter.LengthFilter(maxLength), new EmojiInputFilter()};
    }

    /**
     * 禁止输入表情
     */
    public static class EmojiInputFilter implements InputFilter {
        private String emoji3 = "[\\u4E00-\\u9FA5\\uFF00-\\uFFFF\\u3000-\\u30200-9a-zA-Z%.]*";

        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            if (Pattern.matches(emoji3, source)) {
                return source;
            }
            return "";
        }
    }

}
